package com.ml.mall.api;

import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.job.IBaseJobService;
import com.ml.mall.job.pojo.ScheduleJobDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/job")
@Slf4j
public class JobController {

    @Autowired
    private IBaseJobService iBaseJobService;

    @PostMapping("/add")
//    @RequiresPermissions(PermissionConst.JOB_ADD)
    public ApiRestResult save(ScheduleJobDTO scheduleJobDTO){
        log.info("新增任务");
        iBaseJobService.addJob(scheduleJobDTO);
        return ApiRestResult.ok();
    }
    @PostMapping("/list")
//    @RequiresPermissions(PermissionConst.JOB_LIST)
    public ApiRestResult list(String jobName,Integer pageNo,Integer pageSize){
        log.info("任务列表");
        //iBaseJobService.listQuartzJob(jobName, pageNo, pageSize);
        return ApiRestResult.ok();
    }

    @PostMapping("/trigger")
//    @RequiresPermissions(PermissionConst.JOB_TRIGGER)
    public  ApiRestResult trigger(String jobName, String jobGroup) {
        log.info("触发任务");
        iBaseJobService.triggerJob(jobName, jobGroup);
        return ApiRestResult.ok();
    }

    @PostMapping("/pause")
//    @RequiresPermissions(PermissionConst.JOB_PAUSE)
    public  ApiRestResult pause(String jobName, String jobGroup) {
        log.info("暂停任务");
        iBaseJobService.pauseJob(jobName, jobGroup);
        return ApiRestResult.ok();
    }

    @PostMapping("/resume")
//    @RequiresPermissions(PermissionConst.JOB_RESUME)
    public  ApiRestResult resume(String jobName, String jobGroup) {
        log.info("恢复任务");
        iBaseJobService.resumeJob(jobName, jobGroup);
        return ApiRestResult.ok();
    }

    @PostMapping("/remove")
//    @RequiresPermissions(PermissionConst.JOB_REMOVE)
    public  ApiRestResult remove(String jobName, String jobGroup) {
        log.info("移除任务");
        iBaseJobService.deleteJob(jobName, jobGroup);
        return ApiRestResult.ok();
    }
}